<template>
  <div class="main">
    <!-- 搜索框 -->
    <div class="search">
      <router-link to="/search">
        <div class="iconfont">&#xe602;</div>
        <input type="text" placeholder="请输入你要搜索的物品" />
      </router-link>
      <button>搜索</button>
    </div>
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in imgData" :key="item">
        <img :src="item" alt="" />
      </van-swipe-item>
    </van-swipe>
    <!-- logo图标 -->
    <div class="productClassification">
      <div class="production">
        <ul class="logo-list">
          <li v-for="(el,index) in logoData" :key="index">
            <img :src="el.logoUrl" />
            <span>{{ el.name }}</span>
          </li>
        </ul>
      </div>
    </div>
    <!-- 热门推荐 -->
    <div class="productList">
      <div class="title">热门推荐</div>
      <ul>
        <router-link :to="{ path: '/proDetails', query: { i: i } }">
          <li
            v-for="(item, index) in productList"
            :key="index"
            @click="click(item.id)"
            v-show="item.isShow"
          >
            <img :src="item.bannerurl[0]" alt="" />
            <div class="content">
              <div class="name">{{ item.name }}</div>
              <div class="news">{{ item.introduce }}</div>
            </div>
          </li>
        </router-link>
      </ul>
    </div>
  </div>
</template>
<script>
import {logoList,commandList} from '@/assets/api/index'
import { mapMutations, mapState } from 'vuex';
export default {
  data() {
    return {
      i: 0,
      imgData: [
        require("../assets/img/1.jpg"),
        require("../assets/img/2.jpg"),
        require("../assets/img/3.jpg"),
        require("../assets/img/4.jpg"),
      ],
      logoData:null,
      productList:null
    };
  },
  computed:{
    ...mapState(['product'])
  },
  methods: {
    ...mapMutations(['setProduct']),
    click(i) {
      this.i = i - 1;
    },
  },
  mounted(){
    logoList().then(res=>{
      // console.log(res);
      this.logoData = res.data.list
    })
    if(!this.product){
      commandList().then(res=>{
        // console.log(res);
        this.productList = res.data.list
        this.$store.commit('setProduct',this.productList)
      })
    }else{
      this.productList = this.product
    }
    
  }
};
</script>

<style scoped lang="scss">
.main {
  padding-top: 60px;
  padding-bottom: 80px;
  // 搜索框
  .search {
    margin-top: -1px;
    width: 100%;
    height: 40px;
    background: #fccde7;
    position: relative;
    padding: 5px;
    box-sizing: border-box;
    .iconfont {
      width: 30px;
      height: 30px;
      position: absolute;
      left: 20px;
      top: 5px;
      font-size: 20px;
      text-align: center;
      line-height: 30px;
      color: #f77625;
    }
    input {
      display: block;
      width: 95%;
      height: 30px;
      border-radius: 20px;
      border: 2px solid #f77625;
      margin: 0 auto;
      padding: 0 20px 0 40px;
      box-sizing: border-box;
      outline: none;
      font-size: 16px;
    }
    button {
      position: absolute;
      top: 8px;
      right: 18px;
      background: #f77625;
      height: 24px;
      font-size: 14px;
      border-radius: 20px;
      color: #fff;
      padding: 3px 15px;
      border: none;
    }
  }
  .my-swipe .van-swipe-item {
    width: 100%;
    height: 300px;
    text-align: center;
    img {
      width: 100%;
      height: 300px;
    }
  }
  .productClassification {
    background: #fccde7;
    width: 100%;
    height: 200px;
    padding: 5px 10px;
    box-sizing: border-box;
    .production {
      width: 100%;
      height: 100%;
      background: #fff;
      border-radius: 20px;
      display: flex;
      flex-direction: column;
      flex-wrap: wrap;
      .logo-list {
        display: flex;
        justify-content: space-between;
        height: 95px;
        flex-wrap: wrap;
        li {
          flex-basis: 25%;
          height: 95px;
          display: flex;
          flex-direction: column;
          img {
            width: 100%;
            height: 70px;
            border-radius: 20px;
          }
          span {
            height: 20px;
            display: block;
            font-size: 12px;
            padding: 0;
            // line-height: 20px;
            text-align: center;
          }
        }
      }
    }
  }
  .productList {
    width: 100%;
    background: #fccde7;
    padding: 5px 10px;
    box-sizing: border-box;
    .title {
      margin: 0 auto;
      width: 200px;
      height: 50px;
      background: #fa6ba1;
      border-radius: 20px;
      line-height: 50px;
      text-align: center;
      font-size: 22px;
      color: #fff;
      margin-bottom: 10px;
    }
    ul {
      border-radius: 20px;
      width: 100%;
      background: #fff;
      a {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        li {
          flex-basis: 50%;
          height: 250px;
          position: relative;
          border: 3px solid #fff;
          box-sizing: border-box;
          border-radius: 20px;
          img {
            border-radius: 20px;
            width: 100%;
            height: 100%;
          }
          .content {
            width: 100%;
            height: 100px;
            background: rgba(0, 0, 0, 0.5);
            position: absolute;
            bottom: 0;
            left: 0;
            color: #fff;
            padding: 0 10px;
            box-sizing: border-box;
            border-bottom-left-radius: 20px;
            border-bottom-right-radius: 20px;
            .name {
              width: 100%;
              height: 30px;
              line-height: 30px;
              font-size: 18px;
            }
            .news {
              width: 100%;
              height: 70px;
              line-height: 23px;
              color: rgb(180, 180, 180);
              font-size: 14px;
              display: -webkit-box;
              overflow: hidden;
              text-overflow: ellipsis;
              -webkit-box-orient: vertical;
              -webkit-line-clamp: 3;
            }
          }
        }
      }
    }
  }
}
</style>